//相关数据结构和接口请参考 https://192.168.1.99/svn/MIDISV3/Software/trunk/public/inf/devModel
const systemModule = {
  namespaced: true,
  state: {
    devName: '',
    devModel: '',
    portRange: {},
    autoCfg: {},
    auth: {
      username:'',
      password:'',
      remember: false
    },
    companyInfo: {
      logo: 'custom/logo.png', //去下载		//下载logo前需要向服务器发送准备logo资源命令
      company: "TENDZONE",
      companyAddr: "深圳市南山区朗山路华瀚科技C座202",
      site: "http://www.tendzone.com"
    },
    productInfo: {
      name: '',
      MAC: '',
      sn: '',
      modelNameId: '',
    },
    sysTime: {
      sysTime: '1900-01-01T00:00:00',
      NTPAddr: '192.168.1.1',
      autoSetTime: true,
    },
    diskInfo: {
      cnt: 0,
      disks: [{
        index: 0,
        name: '分区名称',
        patition: '磁盘分区设备',
        mountPath: '磁盘分区挂载路径',
        type: '分区文件系统类型',
        totalSize: 100,
        freeSize: 50,
        readonly: false,
        info: {
          index: 0,
          name: '分区名称',
          patition: '磁盘分区设备',
          mountPath: '磁盘分区挂载路径',
          type: '分区文件系统类型',
          totalSize: 100,
          freeSize: 50,
          readonly: false,
        }
      }]
    },
    netsInfo: {
      cnt: 0,
      nets: [{
        index: 0,
        ifName: 'eth0',
        enable: true,
        type: 'DHCP',
        ipaddr: '192.168.1.1',
        netmask: '255.255.255.0',
        gateway: '192.168.1.1',
        mainDnsServerAddr: '',
        subDnsServerAddr: '',
        info:{}
      }]
    },
    runningInfo: {
      uptime: 60, //单位：s
      cpuLoad: 50, //0~100
      procCnt: 50,
      totalRamSize: 100, //（字节）
      freeRamSize: 50, //（字节）
    },
    JWT:"",
    AgingState: [
      {
        status: "", setDuration: 0, currDuration: 0, totalDuration: 0
      }
    ],
    clientId: '',
    topics: [],
    isSpecialType: false,
    curTopic:'zhishen'
  },
  mutations: {
    getspecialtype(state, res) {
      state.curTopic = res ? 'mediaapp' : 'zhishen';
      state.isSpecialType = res;
    },
    GET_COMPANY_INFO(state, res) {
      
      state.companyInfo = res;
    },
    GETPRODUCTINFO(state, res) {
      state.productInfo = res;
    },
    GETSYSTEMTIME(state, res) {
      state.sysTime.sysTime = res;
    },
    AUTOFITTIME(state, res) {
      state.sysTime.NTPAddr = res.serverAddr;
      state.sysTime.autoSetTime = res.autoSetTime;
    },
    GET_DISKCNT(state, res) {
      state.diskInfo.cnt = res;
    },
    GET_DISKINFO(state, res) {      
      if (res) {
        if(res.patitions){
          for(var i =0;i<res.patitions.length;i++){
            res.patitions[i].index = i
          }
        }
        state.diskInfo.disks.push(res)
      } else {
        state.diskInfo.disks = []
      }
    },
    GET_NETSCNT(state, res) {

      state.netsInfo.cnt = res;
    },
    GET_NETSINFO(state, res) {
      if (res) {
        if (state.netsInfo.nets[res.index]) {
          //动态新增属性并赋值
          for (var name in res) {
            state.netsInfo.nets[res.index][name] = res[name]
          }
        } else {
          state.netsInfo.nets.push(res)
        }

      } else {
        state.netsInfo.nets = []
      }
    },
    GET_NETS_STATUS(state, res) {
      state.netsInfo.nets[res.index].info = res.info
    },
    GET_JWT(state, res) {      
      state.JWT = res;
    },
    GET_AGING_STATES(state, res) {     
      
      state.AgingState = []
      state.AgingState.push(res)
    },
    SET_AUTHINFO(state, res) {            
      state.auth = res;
    },
    GET_CLIENTID(state, res) {           
      state.clientId = res;
    },
    GET_TOPICS(state, res) { 
      if(res){
        state.topics = state.topics.concat(res)
      } else{
        state.topics = []
      }       
    },
  },
  actions: {
    //公司信息
    getCompanyInfo({
      commit
    }, res) {
      commit('GET_COMPANY_INFO', res);
    },
    //产品信息
    getProductInfo({
      commit
    }, res) {
      commit('GETPRODUCTINFO', res);
    },
    //系统时间
    getSystemTime({
      commit
    }, res) {
      commit('GETSYSTEMTIME', res);
    },
    //自动对时
    autoFitTime({
      commit
    }, res) {
      commit('AUTOFITTIME', res);
    },
    //硬盘数
    getDiskCnt({
      commit
    }, res) {
      commit('GET_DISKCNT', res);
    },
    getDiskInfo({
      commit
    }, res) {
      commit('GET_DISKINFO', res);
    },
    //网卡数
    getNetsCnt({
      commit
    }, res) {
      commit('GET_NETSCNT', res);
    },
    getNetsInfo({
      commit
    }, res) {
      commit('GET_NETSINFO', res);
    },
    getNetsStatus({
      commit
    }, res) {
      commit('GET_NETS_STATUS', res);
    },
    getJWT({
      commit
    }, res) {
      commit('GET_JWT', res);
    },
    getAgingStates({
      commit
    }, res) {
      commit('GET_AGING_STATES', res);
    },
    setAuthInfo({
      commit
    }, res) {
      commit('SET_AUTHINFO', res);
    },
    getClientId({
      commit
    }, res) {
      commit('GET_CLIENTID', res);
    },
    getTopics({
      commit
    }, res) {
      commit('GET_TOPICS', res);
    },
  }
};

export default systemModule
